/**
 * @fileoverview
 * TODO doc me
 */

function initialiseApplication() {
	
	var logReader = new YAHOO.widget.LogReader("logger");
	
	log("instantiate a service for the flyted image widget");
	var service = new flyui.flyted.Service("../../../data/flyted");
	
	log("instantiate a renderer for the flyted image widget");
	var renderPane = document.getElementById("flytedImageWidget");
	var renderer = new flyui.flyted.ImageWidget.DefaultRenderer();
	renderer.setCanvas(renderPane);
	
	log("instantiate a flyted image widget");
	widget = new flyui.flyted.ImageWidget(service, renderer);
	
	log("hook form submission to widget call");
	YAHOO.util.Event.addListener("queryForm", "submit", onFormSubmit);
	
	log("application loaded, showing main pane");
	flyui.mvcutils.hide(document.getElementById("loadingPane"));
	flyui.mvcutils.show(document.getElementById("applicationPane"));
}

function onFormSubmit(event) {
	log("form submitted");
	
	var query = document.getElementById("queryInput").value;
	log("query: "+query);
	
	var flytedMode = document.getElementById("flytedInputMode").checked;
	log("flyted mode: "+flytedMode);

	if (flytedMode) {
		widget.findImagesByFlytedGeneName(query);
	} else {
		widget.findImagesByFlybaseGeneID(query);
	}
}

YAHOO.util.Event.onDOMReady(initialiseApplication);